package com.yeyuanqi.hottop.controller;

import com.yeyuanqi.hottop.common.Result;
import com.yeyuanqi.hottop.entity.SysAnnouncement;
import com.yeyuanqi.hottop.entity.SysChart;
import com.yeyuanqi.hottop.entity.SysHotsplatform;
import com.yeyuanqi.hottop.entity.SysWeb;
import com.yeyuanqi.hottop.service.*;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 系统网站信息控制器
 * @author yeyuanqi
 * @since 2021-12-24
 */
@RestController
@RequestMapping("/sys")
public class SysInfoController {

    @Autowired
    private SysWebService sysWebService;

    @Autowired
    SysAnnouncementService sysAnnouncementService;

    @Autowired
    SysChartService sysChartService;

    @Autowired
    SysHotsplatformService sysHotsplatformService;



    /**
     * @return 热搜平台的爬取显示信息
     */
    @GetMapping("/webinfo")
    public Result getWebInfo(){
        //redis只缓存isshow==1的
//        List<Object> sys_webInfo = redisService.lRange("Sys_WebInfo", 0, -1);
//        if (sys_webInfo.size()!=0){
//            return Result.succ(sys_webInfo);
//        }
        List<SysWeb> sysInfos = sysWebService.list();
        List<SysWeb> sysInfo = new ArrayList<>();
        for (SysWeb info:sysInfos){
            if (info.getIsshow()==1){
                sysInfo.add(info);
            }
        }
        return Result.succ(sysInfo);
    }

    /**
     * @return 图表信息
     */
    @GetMapping("/chartinfo")
    public Result getChartInfo(){
//        List<Object> sys_chartInfo = redisService.lRange("Sys_ChartInfo", 0, -1);
//        if (sys_chartInfo.size()!=0){
//            return Result.succ(sys_chartInfo);
//        }
        List<SysChart> sysInfos = sysChartService.list();
        List<SysChart> sysInfo = new ArrayList<>();
        for (SysChart info:sysInfos){
            if (info.getIsshow()==1){
                sysInfo.add(info);
            }
        }
        return Result.succ(sysInfo);
    }

    /**
     * @return 更多热搜平台信息
     */
    @GetMapping("/hotsplatforminfo")
    public Result getHotsplatformInfo(){
//        List<Object> sys_hotsplatformInfo = redisService.lRange("Sys_HotsplatformInfo", 0, -1);
//        if (sys_hotsplatformInfo.size()!=0){
//            return Result.succ(sys_hotsplatformInfo);
//        }
        List<SysHotsplatform> sysInfos = sysHotsplatformService.list();
        List<SysHotsplatform> sysInfo = new ArrayList<>();
        for (SysHotsplatform info:sysInfos){
            if (info.getIsshow()==1){
                sysInfo.add(info);
            }
        }
        return Result.succ(sysInfo);
    }

    /**
     * @return 公告信息
     */
    @GetMapping("/announcementinfo")
    public Result getAnnouncementInfo(){
//        List<Object> sys_announcementInfo = redisService.lRange("Sys_AnnouncementInfo", 0, -1);
//        if (sys_announcementInfo.size()!=0){
//            return Result.succ(sys_announcementInfo);
//        }
        List<SysAnnouncement> sysInfos = sysAnnouncementService.list();
        List<SysAnnouncement> sysInfo = new ArrayList<>();
        for (SysAnnouncement info:sysInfos){
            if (info.getIsshow()==1){
                sysInfo.add(info);
            }
        }
        return Result.succ(sysInfo);
    }


}
